package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.customer.CustomerQueryDTO;
import com.qk.entity.Customer;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.CustomerService;
import com.qk.vo.customer.CustomerQueryVO;
import com.qk.vo.customer.CustomerVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author lyl
 * @created 2025/10/18 21:24
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/customers")
@SuppressWarnings("all")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result getListByPage(CustomerQueryDTO queryDTO) {
        log.info("分页查询客户queryDTO: {}", queryDTO.toString());
        PageResult<CustomerQueryVO> pageResult = customerService.getListByPage(queryDTO);
        return Result.success(pageResult);
    }
    @LogAnno
    @PostMapping
    public Result addCustomer(@RequestBody  Customer customer) {
        log.info("新增客户: {}", customer.toString());
        customerService.addCustomer(customer);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        log.info("根据ID查询客户详情: {}", id);
        CustomerVO customer = customerService.getCustomerById(id);
        return Result.success(customer);
    }
    @LogAnno
    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer) {
        log.info("更新客户: {}", customer.toString());
        customerService.updateCustomer(customer);
        return Result.success();
    }

}
